﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModbusTest.Config;

namespace ModbusTest
{
    public partial class FrmModuleConfig : Form
    {
        public event Action<int,string> OnConfig; 
        int EditMode = 0;
        ModuleConfig _cfg;
        public FrmModuleConfig(ModuleConfig cfg,int Mode=0)
        {
            InitializeComponent();
            EditMode = Mode;
            _cfg = cfg;
            if (EditMode == 0)
            {
                propertyGrid1.Enabled = false;
            }
        }
        private void FrmModuleConfigAdd_Load(object sender, EventArgs e)
        {
            if (EditMode==0)
            {
                this.tableLayoutPanel1.RowStyles[1].Height = 0;
            }
            this.propertyGrid1.SelectedObject = _cfg;
        }

        private void btnYes_Click(object sender, EventArgs e)
        {
            OnConfig(1,_cfg.Name);
            ModuleConfigTool.Save(_cfg);
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            OnConfig(0,_cfg.Name);
            Close();
        }

    }
}
